import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.EventLoop;

import java.util.concurrent.TimeUnit;

public class ClientReConnectHandler extends ChannelInboundHandlerAdapter {

    private Client client;


    public ClientReConnectHandler(Client client) {
        this.client = client;
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("channelInactive");
        final EventLoop loop = ctx.channel().eventLoop();
        loop.schedule(() -> {
            try {
                System.out.println("重连服务器！");
                client.doConnect();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, 3, TimeUnit.SECONDS);
    }
}
